package com.situ.mall.lambda;

import com.situ.mall.demo.Student;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;

public class LambdaDemo {
    public static void main(String[] args) {
        Thread thread = new Thread(new MyRunnable());
        thread.start();
        new Thread(new MyRunnable()).start();
        // 匿名内部类做了哪些事情
        // 1、定义一个没有名字的类
        // 2、这个类实现了Runnable接口
        // 3、创建了这个类对象
        // 使用匿名内部类的语法是冗余的
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());;
            }
        }, "myThread").start();

        // 其实我们最关注的是run方法和里面要执行的代码.
        // Lambda表达式体现的是函数式编程思想,只需要将要执行的代码放到函数中
        //（参数列表）->{
        // }
        new Thread(() -> {
            System.out.println("LambdaDemo.main");
        }).start();

        new Thread(() -> System.out.println("LambdaDemo.main")).start();

    }

    @Test
    public void test1() {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(1, "张三", 34, "男"));
        list.add(new Student(1, "李四", 45, "男"));
        list.add(new Student(1, "王五", 87, "男"));
        list.add(new Student(1, "赵六", 22, "男"));
        /*Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });*/
        /*Collections.sort(list, (Student o1, Student o2) -> {
            return o1.getAge() - o2.getAge();
        });*/
        Collections.sort(list, (o1, o2) -> o1.getAge() - o2.getAge());
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
